package esb.chapter2.jbi;

import javax.jbi.component.Component;
import javax.jbi.component.ComponentLifeCycle;
import javax.jbi.component.ServiceUnitManager;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.servicedesc.ServiceEndpoint;

import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;

/**
 * This component defines how our component looks and how it can be accessed.
 * 
 * @author nl24167
 */
public class HelloJBIComponent implements Component {

	private HelloJBILifeCycle helloJBILifecycle;

	/**
	 * Return the class describing this components lifecycle.
	 */
	public ComponentLifeCycle getLifeCycle() {
		if (helloJBILifecycle == null) {
			helloJBILifecycle = new HelloJBILifeCycle(); 
		}
		return helloJBILifecycle;
	}

	/**
	 * The servicedescription describes how this services can be used. There is no
	 * interface describing this as it is just a XML object. We don't implement this
	 * for this component.
	 */
	public Document getServiceDescription(ServiceEndpoint arg0) {
		return null;
	}

	/**
	 * It's possible to deploy components inside this component. If we want that
	 * functionality we can define a ServiceUnitManager. Since this is a very basic
	 * component we won't do this.
	 */
	public ServiceUnitManager getServiceUnitManager() {
		return null;
	}

	/**
	 * Used for policy reasons. Here we can decide whether we want to
	 * service a certain consumer. We don't implement a policy so we
	 * allow everything.
	 */
	public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0,
			MessageExchange arg1) {
		return true;
	}

	/**
	 * Used for policy reasons. Here we can decide whether we want to
	 * service a certain producer. We don't implement a policy so we
	 * allow everything.
	 */
	public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0,
			MessageExchange arg1) {
		return true;
	}

	/**
	 * This allows you to return a specific serviceEndpoint.
	 */
	public ServiceEndpoint resolveEndpointReference(DocumentFragment fragment) {
		return null;
	}

}
